<?php

/**
 * message form.
 *
 * @package    forumCDE
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class messageForm extends BasemessageForm
{
  public function configure()
  {
  	$user = sfContext::getInstance()->getUser()->getUserProfile();
  	$this->setDefault('created_by_id', $user->id);
  	$this->getWidget('created_by_id')->setAttribute('disabled', 'true');
  	$q = $this->getWidget('service_id')->getOption('query');
  	$q2 = $q->copy();
  	$root = $q2->getRootAlias();
  	$q2->innerJoin($root.'.groupe g')
		->innerJoin('g.personnes p')
	   	->where('p.personne_id = '.$user->id );
	if(!sfContext::getInstance()->getUser()->isSuperAdmin()){
  		$this->getWidget('service_id')->setOption('query', $q2);
	}
  	$results = $q2->execute();
  	if($results->count()==1){
  		$this->setDefault('service_id', $results[0]['id']);
	  	if(!sfContext::getInstance()->getUser()->isSuperAdmin()){
	  		$this->getWidget('service_id')->setAttribute('disabled', 'true');
	  	}
	 }
  	
  }
}
